package com.aaa.controller.api;


import com.aaa.entity.CheckItem;
import com.aaa.entity.User;
import com.aaa.service.UserService;
import com.aaa.vo.Result;
import com.aaa.vo.UserVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("system/api/user")
public class ApiUserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getInfo")
    public Result<User> getInfo(){
        return userService.getInfo();
    }
    //初始化用户列表
    @PostMapping("/searchUser/{currentPage}/{pageSize}")
    public Result<IPage<User>> searchUser(@PathVariable Integer currentPage,
                                          @PathVariable Integer pageSize,
                                          @RequestBody UserVo userVo){
        return userService.searchUser(currentPage,pageSize,userVo);
    }
    //添加啊修改
    @PostMapping("/addOrUpd")
    public Result<String> addOrUpdUser(@RequestBody User user){
        return userService.addOrUpdUser(user);
    }

    //查询详情
    @GetMapping("/queryById/{id}")
    public Result<User> queryById(@PathVariable Long id){
        return userService.queryById(id);
    }


    @PostMapping("/loginOut")
    public Result<String> loginOut(){
        return userService.loginOut();
    }

    @PostMapping("/updPass")
    public Result<String> updPass(@RequestBody Map<String,Object> map){
        System.out.println("map = " + map);
        String oldPass = (String) map.get("oldPass");
        String newPass = (String) map.get("newPass");
        return userService.updPass(oldPass,newPass);
    }
    @GetMapping("retPass/{uid}")
    public Result<String> retPass(@PathVariable Long[] uid){
        return userService.retPass(uid);
    }

}
